package com.bjsj.pro.tools;

import android.Manifest;
import android.app.Activity;
import android.widget.Toast;

import com.hjq.permissions.OnPermission;
import com.hjq.permissions.Permission;
import com.hjq.permissions.XXPermissions;

import java.util.List;

public class PermissionUtils
{
    //获取SD卡权限
  public static void  getSDtorPermisstion(final Activity mcontext, final Permissions getPm ){

          Toast.makeText(mcontext, "要去获取权限", Toast.LENGTH_SHORT).show();
          XXPermissions.with(mcontext)
                  .permission(Permission.Group.STORAGE)
                  .request(new OnPermission() {

                      @Override
                      public void hasPermission(List<String> granted, boolean isAll) {

                          if (getPm!=null) {
//                                                获取权限成功
                              getPm.getPermission(isAll);
//
                          }
                      }

                      @Override
                      public void noPermission(List<String> denied, boolean quick) {
                          if(quick) {
//                                                Toast.makeText(activity, "被永久拒绝授权，请手动授予权限", Toast.LENGTH_SHORT).show();
                              //如果是被永久拒绝就跳转到应用权限系统设置页面
                              XXPermissions.startPermissionActivity(mcontext);
                          }else {
//                                                获取权限失败

                          }
                      }
                  });
  }
    //获取SD卡权限
    public static void  getLocationtorPermisstion(final Activity mcontext, final Permissions getPm ){

        Toast.makeText(mcontext, "要去获取权限", Toast.LENGTH_SHORT).show();
        XXPermissions.with(mcontext)
                .permission(Manifest.permission.ACCESS_COARSE_LOCATION)
                .request(new OnPermission() {

                    @Override
                    public void hasPermission(List<String> granted, boolean isAll) {

                        if (getPm!=null) {
//                                                获取权限成功
                            getPm.getPermission(isAll);
//
                        }
                    }
                    @Override
                    public void noPermission(List<String> denied, boolean quick) {
                        if(quick) {
//                                                Toast.makeText(activity, "被永久拒绝授权，请手动授予权限", Toast.LENGTH_SHORT).show();
                            //如果是被永久拒绝就跳转到应用权限系统设置页面
                            XXPermissions.startPermissionActivity(mcontext);
                        }else {
//                                                获取权限失败

                        }
                    }
                });


    }
   private  Permissions getPm;
    public void setGetPm(Permissions getPm) {
        this.getPm = getPm;
    }

    public interface Permissions{
      void getPermission(boolean isAll);

  }
}
